package leetcode;

import util.Tree;
import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0700.java
 * @Author : WangRuoyu
 * @Date 2023/10/23 20:36
 */

public class Q0700 {
    public TreeNode searchBST(TreeNode root, int val) {
        if (root == null) {
            return null;
        } else if (root.val == val) {
            return root;
        } else {
            if (val > root.val) return searchBST(root.right, val);
            else return searchBST(root.left, val);
        }
    }

    public static void main(String[] args) {
        Q0700 sl = new Q0700();
        String[] root = {"4", "2", "1", null, null, "3", null, null, "7", null, null};
        int val = 2;
        TreeNode tree = Tree.createTreeByPreorder(root);
//        Tree.traversal(tree);
        Tree.preorderTraversal(sl.searchBST(tree, val));
    }
}